<html>
<head>
<#assign basePath=request.contextPath>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <link href="${basePath}/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/font-awesome.min.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/form.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/css/good.lzy.css" rel="stylesheet">
    <link href="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css"
          rel="stylesheet">
    <style>
       
    </style>
</head>
<body>
<div class="content-header">
    <h5>
        卡券宝 &gt; 介绍卡券 &gt; <strong>介绍卡券</strong>
    </h5>
</div>

<div class="panel panel-lzy">
    <div class="panel-body">
        <h5 class="tips-lzy">操作提示</h5>
        <ul class="tips-list-lzy">
            <li><span>◆&nbsp;<span>标识“<font color="red">*</font>”的选项为必填项，其余为选填项。</span></span></li>
        </ul>
    </div>
</div>

<div id="page-wrapper">
    <div class="panel panel-f5">
        <div class="panel-body row">
            <form id="Form" class="form-horizontal" method="post">
                <input type="hidden" id="_ctx" value="${basePath}"/>

                <div class="form-group">
                    <span class="control-label col-sm-2 col-xs-4">产品介绍：</span>
                    <div class="col-sm-9 col-xs-8 add-box image-text">
                    <#if (dto.detailImages)??>
                        <#list dto.detailImages as imageText>
                            <#if imageText.type == 1>
                                <div class="text-box">
                                    <textarea data-id="0" name='detailImages[0].path' maxlength="1900" rows="3"
                                              cols="50" class="form-control"
                                              placeholder="最多输入2000字">${imageText.path!}</textarea>
                                    <input class="sort" name='detailImages[0].sort' value="0" type="hidden"/>
                                    <input name='detailImages[0].type' value="1" type="hidden"/>
                                </div>
                            <#elseif imageText.type == 2>
                                <div class="text-box">
                                    <div class="upload-box">
                                        <input class="obj-input" name="detailImages[1].path" value="${imageText.path!}"
                                               type="hidden">
                                        <img class="obj-img" src="${imageText.path!}">
                                        <span class="input-file-edit">
                                            <input data-id="1" type="file" data-action="goods"
                                                   data-image="detailImages[1].path" class="no text field"
                                                   onchange="uploadImg(this)">
                                        </span>
                                        <input class="sort" name='detailImages[1].sort' value="1" type="hidden"/>
                                        <input name='detailImages[1].type' value="2" type="hidden"/>
                                    </div>
                                </div>
                            </#if>
                        </#list>
                    <#else>
                        <div class="text-box">
                            <textarea data-id="0" name='detailImages[0].path' maxlength="1900" rows="3" cols="50"
                                      class="form-control" placeholder="最多输入2000字"></textarea>
                            <input class="sort" name='detailImages[0].sort' value="0" type="hidden"/>
                            <input name='detailImages[0].type' value="1" type="hidden"/>
                        </div>
                        <div class="text-box">
                            <div class="upload-box">
                                <input class="obj-input" name="detailImages[1].path" value="" type="text">
                                <img class="obj-img" src="" style="display:none">
                                <span class="input-file">
								    <input data-id="1" type="file" data-action="goods" data-image="detailImages[1].path"
                                           class="no text field" onchange="uploadImg(this)">
							    </span>
                                <input class="sort" name='detailImages[1].sort' value="1" type="hidden"/>
                                <input name='detailImages[1].type' value="2" type="hidden"/>
                            </div>
                        </div>
                    </#if>
                    </div>
                </div>
               <br />
                <div class="form-group">
                    <span class="control-label col-sm-4 col-xs-4"></span>
                    <div class="col-sm-8 col-xs-8">
                    <#if dto??>
                        <button type="button" class="btn btn-success" onclick="submitFormEdit();"><i
                                class="fa fa-check"></i>提交
                        </button>
                    <#else>
                        <button type="button" class="btn btn-success" onclick="submitForm();"><i
                                class="fa fa-check"></i> 提交
                        </button>
                    </#if>
                        <button type="button" class="btn btn-info" onclick="goBack()"><i class="fa fa-close"></i>返回
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div id="depart-box" style="display: none;">
<#if classifyList?? && classifyDto??>
<#list classifyList as cla>
    <label><input type="radio" name="classifyName" value="${cla.id!}" <#if cla.id == classifyDto.id>checked</#if>>
        <span>${cla.name!}</span></label>
</#list>
<#else>
<#list classifyList as cla>
    <label><input type="radio" name="classifyName" value="${cla.id!}"> <span>${cla.name!}</span></label>
</#list>
</#if>
    <div class="bot">
        <button type="button" class="btn btn-success">确定</button>
    </div>
</div>

<script src="${basePath}/bootstrap/js/jquery.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="${basePath}/bootstrap/plugin/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript"
        src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap-validator/0.5.3/js/language/zh_CN.js"></script>
<script type="text/javascript">
    $(window).bootstrapValidator || document.write('<script src="${basePath}/bootstrap/js/bootstrapValidator.min.js"><\/script>' +
            '<script src="${basePath}/bootstrap/js/bootstrapValidator-zh_CN.js"><\/script>');
</script>
<script src="${basePath}/bootstrap/js/common.js" type="text/javascript"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript"
        src="${basePath}/bootstrap/plugin/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${basePath}/bootstrap/js/campsite.js" type="text/javascript"></script>
<script>

    function goBack() {
        window.location.href = "${basePath}/admin/product/info"
    }

    //新增
    function submitForm() {
        var bsVal = $("#Form").data('bootstrapValidator');
        bsVal.validate();
        if (bsVal.isValid()) {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '${basePath}/admin/product/info/save',
                data: $("#Form").serialize(),
                success: function (data) {
                    if (data.code == '0') {
                        layer.alert('操作成功', {
                            icon: 1
                        }, function () {
                            window.location.href = '${basePath}/admin/product/info';
                        })
                    } else {
                        layer.alert(data.desc, {
                            icon: 5
                        });
                    }
                },
                error: function () {
                    layer.alert('系统错误', {
                        icon: 5
                    });
                }
            });

        }
        else {
            var smallTop = $("small:visible").eq(0).offset().top - 50;
            $("html,body").animate({scrollTop: smallTop}, 300);
        }
    }

    //编辑
    function submitFormEdit() {

        if (!$("#identity-input").is(":checked")) {
            $("#identityId").val("0")
        }

        var bsVal = $("#Form").data('bootstrapValidator');
        bsVal.validate();
        if (bsVal.isValid()) {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '${basePath}/admin/product/info/update',
                data: $("#Form").serialize(),
                success: function (data) {
                    if (data.code == '0') {
                        layer.alert('操作成功', {
                            icon: 1
                        }, function () {
                            window.location.href = '${basePath}/admin/product/info';
                        })
                    } else {
                        layer.alert(data.desc, {
                            icon: 5
                        });
                    }
                },
                error: function () {
                    layer.alert('系统错误', {
                        icon: 5
                    });
                }
            });

        }
        else {
            var smallTop = $("small:visible").eq(0).offset().top - 50;
            $("html,body").animate({scrollTop: smallTop}, 300);
        }
    }
    //表单验证
    $('#Form').bootstrapValidator({
        fields: {
            XXXX: {
                validators: {
                    notEmpty: {
                        message: '.....'
                    }
                }
            }
        }
    });
</script>
</body>
</html>
